﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;

public partial class codelist : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    //删除


    protected void gv_RowCreated(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton lb = e.Row.FindControl("lbtn_down") as LinkButton;

            int id = (int)gv_record.DataKeys[e.Row.RowIndex].Value;

            string file = Server.MapPath("record/" + id.ToString() + ".rar");
            if (System.IO.File.Exists(file) == false)
            {
                lb.Enabled = false;
            }

        }
    }



    protected void btn_down(object sender, EventArgs e)
    {
        LinkButton lb = sender as LinkButton;
        GridViewRow gvr = (GridViewRow)lb.Parent.Parent;
        int id = (int)gv_record.DataKeys[gvr.RowIndex].Value;
        string file = id.ToString() + ".rar";
        string pfile = Server.MapPath("record/" + file);


        FileInfo fileInfo = new FileInfo(pfile);
        Response.Clear();
        Response.ClearContent();
        Response.ClearHeaders();
        Response.AddHeader("Content-Disposition", "attachment;filename=" + file);
        Response.AddHeader("Content-Length", fileInfo.Length.ToString());
        Response.AddHeader("Content-Transfer-Encoding", "binary");
        Response.ContentType = "application/octet-stream";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
        Response.WriteFile(fileInfo.FullName);
        Response.Flush();
        Response.End();

    }


    protected void bt_recordfind_Click(object sender, EventArgs e)
    {
        string str = ConfigurationManager.ConnectionStrings["DevMgmntConnectionString"].ConnectionString.ToString();
        SqlConnection con = new SqlConnection(str);
        con.Open();
        str = "SELECT a.* ,t1.sCultureName cName,t2.sDepartmentName dName,t3.sProfessionaName pName "  ;
        str+="FROM t_record a left join t_culture t1 on t1.iCulture_ID = a.iCulture_ID ";      
        str+="left join t_department t2 on t2.iDepartment_ID = a.iDepartment_ID ";
        str += "left join t_professiona t3 on t3.iProfessiona_ID = a.iProfessiona_ID  ";
        if (tx_num.Text.Trim() != "")
            str += "where  a.iStaff_ID='" + tx_num.Text.Trim() + "' ";
        else if (tx_name.Text.Trim() != "")
            str += "where  a.sName='" + tx_name.Text.Trim() + "' ";
        SqlDataAdapter da = new SqlDataAdapter(str, con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        gv_record.DataSourceID="";
        gv_record.DataSource = ds;
        
        gv_record.DataBind();
    }
}